{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}

<div class="p-3">
	<form class="layui-form gg-form-bar border-t border-x">
<!--		<div class="layui-input-inline" style="width:300px;">-->
<!--			<input type="text" name="nickname" placeholder="请输入店铺名称" class="layui-input" autocomplete="off"/>-->
<!--		</div>-->
<!--		<div class="layui-input-inline" style="width:300px;">-->
<!--			<input type="text" name="mobile" placeholder="手机号" class="layui-input" autocomplete="off"/>-->
<!--		</div>-->
		<div class="layui-input-inline">
			<select name="status">
				<option value="">提现状态</option>
				<option value="1">申请中</option>
				<option value="2">已通过</option>
				<option value="3">已拒绝</option>
			</select>
		</div>
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
	</form>
	<table class="layui-hide" id="withdraw" lay-filter="withdraw"></table>
</div>

<script type="text/html" id="toolbarDemo">

</script>
<div class="row col-sm-12" style="display:none;" id="show_div">
	<form class="layui-form model-form" lay-filter="submitForm2" style="margin-top: 10px">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">拒绝原因：</label>
				<div class="layui-input-inline">
					<textarea name="explain" id="explain" placeholder="请输入拒绝原因" style="width:350px;" class="layui-textarea jian">{$info['explain']|default=''}</textarea>
				</div>
			</div>
		</div>
		<div class="layui-form-item" style="margin-left: 109px">
			<div class="layui-inline">
				<button class="layui-btn">提交</button>
			</div>
		</div>
	</form>
</div>
<script type="text/html" id="barDemo">
	<div class="layui-btn-group">
		{{#  if(d.status == 1){ }}
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">通过</a>
		<a class="layui-btn layui-btn-xs" lay-event="edit" data-id="{{ d.id }}">拒绝</a>
		{{#  } }}
		<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">提现详情</a>
		<!--        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
	</div>
</script>

{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];

	function gouguInit() {
		var table = layui.table, tool = layui.tool, form = layui.form;
		layui.pageTable = table.render({
			elem: '#withdraw',
			title: '提现列表',
			toolbar: '#toolbarDemo',
			url: '/admin/withdraw/datalist',
			page: true,
			limit: 20,
			cellMinWidth: 140,
			cols: [
				[
				{
					fixed: 'left',
					field: 'id',
					title: '编号',
					align: 'center',
					width: 80
				}, {
					field: 'tx_type',
					title: '类型',
					align: 'center',
					width: 100,
					templet: function (d) {
						var str = "";
						if (d.tx_type == 1) {
							str = '<button type="button" class="layui-btn layui-btn-normal layui-btn-xs">售酒端</button>';

						} else if (d.tx_type == 2) {
							str = '<button type="button" class="layui-btn layui-btn-xs">管理员</button>';
						} else {
							str = '<button type="button" class="layui-btn layui-bg-0 layui-btn-xs">补酒员</button>';
						}
						return str;
					},
				}, {
					field: 'nickname',
					title: '用户',
					align: 'center',
					width: 100
				}, {
					field: 'phone',
					title: '手机号码',
					align: 'center',
					width: 100
				}, {
					field: 'money',
					title: '提现金额',
					align: 'center',
					width: 100
				}, {
					field: 'rate',
					title: '手续费率(%)',
					align: 'center',
					width: 100
				}, {
					field: 'dz_money',
					title: '到账金额',
					align: 'center',
					width: 100
				}, {
					field: 'status',
					title: '提现状态',
					align: 'center',
					width: 100,
					templet: function (d) {
						var str = "";
						if (d.status == 1) {
							str = '<span style="color: #5FB878">待审核</span>';
						} else if(d.status == 2) {
							str = '<span>已通过</span>';
						} else {
							str = '<span style="color: red">未通过</span>';
						}
						return str;
					},
				}, {
					field: 'create_time',
					title: '提交时间',
					align: 'center',
					width: 150
				},
					{
						fixed: 'right',
						field: 'right',
						title: '操作',
						toolbar: '#barDemo',
						width: 186,
						align: 'center'
					}
				]
			]
		});

		//监听表头工具栏事件
		table.on('toolbar(withdraw)', function (obj) {
			if (obj.event === 'add') {
				tool.side("/admin/withdraw/add");
				return false;
			}
		});

		//监听表格行工具事件
		table.on('tool(withdraw)', function (obj) {
			var data = obj.data;
			if (obj.event === 'read') {
				layer.confirm('确认通过吗？', {
					btn: ['确认', '取消'] //可以无限个按钮
				}, function(index, layero){
					layer.load();
					$.post('/admin/withdraw/examine', {id:obj.data.id,type:1}, function(res) {
						layer.closeAll();
						if (res.code == 0) {
							layer.msg(res.msg,{icon:1,time:2000},function(){
								window.location.reload();
							});
						} else {
							layer.msg(res.msg,{icon:2,time:2000},function(){
								window.location.reload();
							});
						}
					},'json');
				}, function(index){
					console.log('取消')
				});
			} else if (obj.event === 'detail') {
				tool.side('/admin/withdraw/read?id='+obj.data.id);

			} else if (obj.event === 'edit') {
				var id = $(this).data('id');
				var index = layer.open({
					type: 1,
					title: ['提示说明'],//数组第二项可以写任意css样式；如果你不想显示标题栏，你可以title: false
					area: '500px',
					content: $('#show_div'),
					success:function(){
						form.on('submit(submitForm2)', function (data) {
							var explain = $("#explain").val();
							$.post('/admin/withdraw/examine', {type:2,id:id,refuse:explain}, function(res) {
								layer.closeAll();
								layer.msg('操作成功',{icon:1,time:1500},function(){
									window.location.reload();
								});
							},'json');
							return false;
						});
					}
				})
			} else if (obj.event === 'del') {
				layer.confirm('确定要删除该记录吗?', {
					icon: 3,
					title: '提示'
				}, function (index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/admin/withdraw/del", {id: data.id}, callback);
					layer.close(index);
				});
			}
			return false;
		});

		//监听搜索提交
		form.on('submit(searchform)', function (data) {
			layui.pageTable.reload({
				where: {
					nickname: data.field.nickname,
					mobile: data.field.mobile,
					status: data.field.status,
				},
				page: {
					curr: 1
				}
			});
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->